<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jq/jquery-1.11.1.js"></script>
<style type="text/css">
#id1{
	color:#F00;
}
</style>
<script type="text/javascript">
$(function(){
	$("#btn").click(function(){
		//用户
		if($.trim($("#username").val()).length==0){
			$("#id1").html("用户名不能为空！");
			$("#username").select();
			$("#username").focus();
			return false;
		}
		
		//密码
		if($.trim($("#pwd").val()).length==0){
			$("#id1").html("密码不能为空！");
			$("#pwd").select();
			$("#pwd").focus();
			return false;
		}
		//用户已登录的情况
		$.ajaxSetup({async:false});	//使其同步执行。ajax默认是异步执行。
		var info="";
		$.post("CheckExists",{username:$("#username").val()},function(data){
			info=data;
		});
		if(info.length>0){
			alert(info);
			return false;
		}
		
		return true;	
	});
});
</script>
</head>
<body>
<a href="main.jsp">主页面</a> <a href="login.jsp">登录页面</a> <a href="online.jsp">在线用户</a> <a href="visitor.jsp">历史访客</a>  <a href="history.jsp">访问记录</a> <br><br>
<form action="Checkit" method="get">
<table width="263" border="1">
  <tr>
    <th colspan="2" align="center">用户登录信息</th>
  </tr>
  <tr>
    <td width="56">用户名</td>
    <td width="191">
      <input type="text" name="username" id="username">
    </td>
  </tr>
  <tr>
    <td>密码</td>
    <td>
      <input type="password" name="pwd" id="pwd">
    </td>
  </tr>
  <tr>
    <td>
      <input type="submit" name="btn" id="btn" value="登录">
    </td>
    <td><div id="id1"></div></td>
  </tr>
</table>
</form>
</body>
</html>